package main.java.com.lee.pattern.masterworker;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2022/2/18
 */
public class Task<R> {
    static AtomicInteger index = new AtomicInteger(1);
    public Consumer<Task<R>> resultAction;

    private int taskId;

    private int workerId;

    R result = null;

    public Task(){
        this.taskId = index.getAndIncrement();
    }

    public void execute() {
        this.result = doExecuted();
        resultAction.accept(this);
    }

    protected R doExecuted() {
        throw new UnsupportedOperationException();
    }

    public void setWorkerId(int workerId) {
        this.workerId = workerId;
    }

    public int getWorkerId() {
        return workerId;
    }

    public int getTaskId() {
        return taskId;
    }

    public R getResult() {
        return result;
    }
}
//13666661422
